package com.zrw.web.controller.sms;

import com.zrw.common.annotation.Log;
import com.zrw.common.core.controller.BaseController;
import com.zrw.common.core.domain.AjaxResult;
import com.zrw.common.core.page.TableDataInfo;
import com.zrw.common.enums.BusinessType;
import com.zrw.sms.domain.SmsCustomerApp;
import com.zrw.sms.service.ISmsCustomerAppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * app信息
 * 
 * @author ruoyi
 */
@RequiredArgsConstructor
@Tag(name = "app管理")
@RestController
@RequestMapping("/sms/customer-app")
public class SmsCustomerAppController extends BaseController {
    private final ISmsCustomerAppService customerAppService;

    /**
     * 获取app列表
     */
    @Operation(summary = "获取app列表")
//    @PreAuthorize("@ss.hasPermi('system:CustomerApp:list')")
    @GetMapping("/list")
    public TableDataInfo<SmsCustomerApp> list(@ParameterObject SmsCustomerApp app) {
        startPage();
        List<SmsCustomerApp> list = customerAppService.selectAppList(app);
        return getDataTable(list);
    }

    /**
     * 根据app编号获取详细信息
     */
    @Operation(summary = "获取app详情")
//    @PreAuthorize("@ss.hasPermi('system:CustomerApp:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable Long appId) {
        return success(customerAppService.selectCustomerAppById(appId));
    }

    /**
     * 新增app
     */
//    @PreAuthorize("@ss.hasPermi('system:CustomerApp:add')")
    @Operation(summary = "新增app")
    @Log(title = "app", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SmsCustomerApp customerApp) {
        customerApp.setCreateBy(getUsername());
        return toAjax(customerAppService.insertCustomerApp(customerApp));
    }

    /**
     * 修改app
     */
//    @PreAuthorize("@ss.hasPermi('system:CustomerApp:edit')")
    @Operation(summary = "修改app")
    @Log(title = "app", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SmsCustomerApp customerApp) {
        customerApp.setUpdateBy(getUsername());
        return toAjax(customerAppService.updateCustomerApp(customerApp));
    }

    /**
     * 删除app
     */
//    @PreAuthorize("@ss.hasPermi('system:CustomerApp:remove')")
    @Operation(summary = "删除app")
    @Log(title = "app", businessType = BusinessType.DELETE)
    @DeleteMapping("/{CustomerAppIds}")
    public AjaxResult remove(@PathVariable Long[] CustomerAppIds) {
        return toAjax(customerAppService.deleteCustomerAppByIds(CustomerAppIds));
    }
}
